/*
 *  Medieval Melee
 *  Copyright (C) 2009 Ben Foote
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Uzebox is a reserved trade mark
*/

#ifndef UNIT_TEST
    #include <uzebox.h>
#else
    #include "unit_test.h"
#endif

#include "graphics.h"
#include "globals.h"

// Internal function prototype.
void GRPHi_DrawBlock(unsigned char x, unsigned char y, unsigned char blocktype, unsigned char animframe);

// Draw the onscreen playfield(s) of blocks.
void GRPH_DrawPlayfield(PLAYFIELD_TYPE tPlayfield, unsigned char layout)
{
  switch(layout)
  {
    // Case for 1 player layout
    case 0:
      for(unsigned char x = 0;x < 6;x++)
      {
        for(unsigned char y = 0;y < 12;y++)
        {
            GRPHi_DrawBlock(1 + (x<<1), 4 + (y<<1), tPlayfield.tField[x][y].ucBlock, 0);
        }
      }
      break;
     
    // Case for 2 players.
    case 1:
      for(unsigned char x = 0;x < 6;x++)
      {
        for(unsigned char y = 0;y < 12;y++)
        {
            GRPHi_DrawBlock(1 + (x<<1),  4 + (y<<1), tPlayfield.tField[x][y].ucBlock, 0);
			GRPHi_DrawBlock(17 + (x<<1), 4 + (y<<1), tPlayfield.tField[x][y].ucBlock, 0);
        }
      }
      break;
  }
}

// Animation not supported...yet.
void GRPHi_DrawBlock(unsigned char x, unsigned char y, unsigned char blocktype, unsigned char animframe)
{
  unsigned char ucTileID = 0;
  
  switch(blocktype)
  {
    case BLANK:
        SetTile(x,   y,  0 );
        SetTile(x+1, y,   0);
        SetTile(x,   y+1, 0);
        SetTile(x+1, y+1, 0);
        return;
  
    case BLUEDIAMOND:
      ucTileID = 1 ; 
      break;
    
    case GREENSQUARE:
      ucTileID = 5 ;
      break;
    
    case PURPLESQUARE:
      ucTileID = 9 ;
      break;
      
    case REDHEART:
      ucTileID = 13 ;
      break;
      
    case YELLOWSTAR:
      ucTileID = 17 ;
      break;
      
    case GREYBOOM:
      ucTileID = 21 ;
      break;
  }  

  SetTile(x,   y,   ucTileID);
  SetTile(x+1, y,   ucTileID + 1);
  SetTile(x,   y+1, ucTileID + 2);
  SetTile(x+1, y+1, ucTileID + 3);
}
